<template>
    <div>
        <el-row :gutter="10" style="margin-bottom: 80px"><!--流式布局-->
            <el-col :span="6">
                <el-card style="color: #409EFF">
                    <div ><i class="el-icon-user-solid"/>温度</div>
                    <div style="padding:10px 0;text-align: center;font-width: bold">
                        20°C
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: #42b983">
                    <div><i class="el-icon-money"/>总营业额</div>
                    <div style="padding:10px 0;text-align: center;font-width: bold">
                        1000w
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: hotpink">
                    <div><i class="el-icon-bank-card"/>利润</div>
                    <div style="padding:10px 0;text-align: center;font-width: bold">
                        500w
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card style="color: lawngreen">
                    <div> <i class="el-icon-s-shop"/>上市倒计时</div>
                    <div style="padding:10px 0;text-align: center;font-width: bold">
                        1000
                    </div>
                </el-card>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="12">
                <div id="main" style="width: 500px;height: 400px;"></div>
            </el-col>
            <el-col :span="12">
                <div id="pie" style="width: 500px;height: 400px;"></div>
            </el-col>
        </el-row>

    </div>
</template>

<script>
    import * as echarts from 'echarts';

    export default {
        name: "Home",
        data() {
            return {}
        },
        mounted() {//页面元素<div id="main">渲染之后再触发
            var chartDom = document.getElementById('main');
            var myChart = echarts.init(chartDom);
            var option = {
                title: {
                    text: '各季度用户用户活跃情况',
                    subtext: '趋势图',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                xAxis: {
                    type: 'category',
                    data: ["第一季度", "第二季度", "第三季度", "第四季度"]
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {name:'111', data: [], type: 'line'},
                    {name:'111', data: [], type: 'bar'},
                    {name:'222', data: [], type: 'line'},
                    {name:'222', data: [], type: 'bar'},
                ]
            };


            //饼图
            var pieDom = document.getElementById('pie');
            var pieChart = echarts.init(pieDom);
            var PieOption = {
                title: {
                    text: 'Referer of a Website',
                    subtext: 'Fake Data',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: 'Access From',
                        type: 'pie',
                        radius: '50%',
                        label: {         //饼图图形上的文本标签
                            normal: {
                                show: true,
                                position: 'inner',   //标签的位置
                                textStyle: {
                                    fontWeight: 300,
                                    fontsize: 16,     //文字的字体大小
                                    color: '#fff'
                                },
                                formatter: '{d}%'
                            }
                        },
                        data: [
                            /*{value: 1048, name: 'Search Engine'},
                            {value: 735, name: 'Direct'},
                            {value: 580, name: 'Email'},
                            {value: 484, name: 'Union Ads'},
                            {value: 300, name: 'Video Ads'}*/  //待填空
                        ],
                        emphasis:
                            {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor:
                                        'rgba(0, 0, 0, 0.5)'
                                }
                            }
                    }
                ]
            };

            this.request.get("/echarts/members").then(res => {
                //折线图
                //填空
                /*option.xAxis.data=res.data.x;
                option.series[0].data=res.data.y;
                option.series[1].data=res.data.y;*/
                // option.xAxis.data=res.data.x;
                option.series[0].data = res.data;
                option.series[1].data = res.data;
                option.series[2].data = [1,2,3,4];
                option.series[3].data = [1,2,3,4];
                //数据准备完毕后再set
                myChart.setOption(option);

                //饼图
                PieOption.series[0].data = [
                    {name: "第一季度", value: res.data[0]},
                    {name: "第二季度", value: res.data[1]},
                    {name: "第三季度", value: res.data[2]},
                    {name: "第四季度", value: res.data[3]},
                ];
                pieChart.setOption(PieOption)
            });


        }
    }
</script>

<style scoped>

</style>